package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.JobDAO;
import com.yang.doctorrecruitment.dto.ReleaseJob;

import java.util.List;
import java.util.Map;

public class ManageJobAction extends ActionSupport{
//    这里需要返回什么？这是一个招聘的列表
    private JSONArray job;
    public String GetJobRelese(){
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");
        List<ReleaseJob> list= JobDAO.getReleseJob(UserID);
        System.out.println(list.toString());


        //为什么这里的数据无法展示呢？
       for(int i=0;i<list.size();i++){
           ReleaseJob releaseJob=list.get(i);
           session.put("jobID"+i+"",releaseJob.getJobID());
       }
        JSONArray array= JSONArray.parseArray(JSON.toJSONString(list));
        job=array;
        return SUCCESS;
    }

    public String GetJobCollectionByUserID(){
        String UserID= (String) ActionContext.getContext().getSession().get("UserID");
//        通过UserID,找到收藏得jobid列表，并通过jobID搜索job信息
        //select * from job where JobID in (select JobID from collection where UserID=22);
        List<ReleaseJob> jobs=JobDAO.getAllCollectionByUserID(UserID);
        JSONArray array= JSONArray.parseArray(JSON.toJSONString(jobs));
        job=array;
        return SUCCESS;
    }

    public JSONArray getJob() {
        return job;
    }

    public void setJob(JSONArray job) {
        this.job = job;
    }
}
